// pages/wx_activity/lottery/lottery.js

const $ = require('../../../utils/utils.js')
const config = require('../../../config.js')
var app = getApp(); 
Page({

    /**
     * 页面的初始数据
     */
    data: {
        lotteryUrl: '',
        hdUserId:'',
        isLoaded:false,
        footerConfig: {
            pageEvent: true,
            loadingText: "正在努力的加载数据...",
            wishCount: 0
        },
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        app.callUserCheck().then(data=>{
            that.getShareInfo()
            that.setData({
                isLoaded:true,
                lotteryUrl: `https://h5.wdb007.com/dev/lottery_demo/html/lottery.html?usertoken=${wx.getStorageSync('usertoken')}&userid=${wx.getStorageSync('userid')}&parentHdUid=${options.hdUserId}`
            })

        }).catch(error => {

        })
        wx.hideShareMenu()
    },

    getShareInfo: function () {
        let that = this
        let params = {
            usertoken: wx.getStorageSync('usertoken'),
            userid: wx.getStorageSync('userid'),
            mobile: wx.getStorageSync('userPhone')
        }
        $.post(config.activityShareInfo, params).then(data => {
            console.log(data)
            wx.showShareMenu()
            that.setData({
                hdUserId: data.detail.hdUserId
            })
        }).catch(error => {

        })
    },


    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: '哇！一次抽奖机会砸中你',
            path: config.page.activityLottery + '?hdUserId=' + this.data.hdUserId,
            imageUrl: 'http://wdb007.oss-cn-hangzhou.aliyuncs.com/wxapp/images/lottery_share.png',
            success: function (share) {
                // 转发成功
                console.log("分享", path);
            },
            fail: function (res) {
                // 转发失败
            }
        }
    }
})